package com.weetop.aklyscan.activity.qingdan;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.Base64;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.weetop.aklyscan.R;

import cc.shinichi.library.tool.utility.ui.ToastUtil;

public class EditDialog1 extends Dialog {
    private Context mContext;
    private ImageView back;
    private EditText edit;
    private TextView button;
    private TextView text;

    public EditDialog1(Context context, TextView text) {
        super(context, R.style.promptDialog);
        setContentView(R.layout.dialog_edit);
        mContext = context;
        this.text = text;
        initVar();
        initView();
        initAttr();
        initAction();
    }

    public void initVar() {
    }

    public void initView() {
        back = findViewById(R.id.back);
        edit = findViewById(R.id.edit);
        button = findViewById(R.id.button);
    }

    public void initAttr() {
    }

    public void initAction() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(edit.getText().toString().trim())) {
                    ToastUtil.getInstance()._short(mContext, "输入不能为空");
                    return;
                }
                float content = Float.valueOf(edit.getText().toString().trim());
                text.setText(edit.getText().toString().trim() + "g");
                dismiss();
            }
        });
    }

    public static void setImage(String imageStr, ImageView image) {
        byte[] decode = Base64.decode(imageStr, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
        image.setImageBitmap(bitmap);
    }
}
